#ifndef __ISO_POSIX_HINT_H__
#define __ISO_POSIX_HINT_H__

class help_introduce
{
    // man help http://man7.org/linux/man-pages/man1/man.1.html
    // 1 表示用户命令和守护进程。
    // 2 表示系统调用和内核服务。
    // 3 表示子例程。
    // 4 表示特殊文件、设备驱动程序和硬件。
    // 5 表示配置文件。
    // 6 表示游戏。
    // 7 表示杂项命令。
    // 8 表示管理命令和守护进程。
    //Example:
    //man man
    //man 2 open
    //
    //https://www.kernel.org/doc/htmldocs/kernel-api/kfifo.html#id-1.8.2
   
};

class help_header
{
// https://pubs.opengroup.org/onlinepubs/9699919799/idx/head.html

//===============basic header file compatible with std c==============

// assert.h       - verify program assertion
// complex.h      - complex arithmetic
// ctype.h        - character types
// errno.h        - system error numbers
// float.h        - floating types
// inttypes.h     - fixed size integer types
// iso646.h       - alternative spellings
// limits.h       - defined constants
// locale.h       - category macros
// math.h         - mathematical declarations
// setjmp.h       - stack environment declarations
// signal.h       - signals
// stdarg.h       - handle variable argument list
// stdbool.h      - boolean type and values
// stddef.h       - standard type definitions
// stdint.h       - integer types
// stdio.h        - standard buffered input/output
// stdlib.h       - standard library definitions
// string.h       - string operations
// time.h         - time types
// ulimit.h       - ulimit commands
// wchar.h        - character handling
// wctype.h       - character classification and mapping utilities

//===============posix head files================================
// aio.h          - asynchronous input and output
// arpa/inet.h    - definitions for internet operations
// cpio.h         - cpio archive values
// dirent.h       - format of directory entries
// fcntl.h        - file control options
// fenv.h         - point environment
// fmtmsg.h       - message display structures
// fnmatch.h      - matching types
// ftw.h          - file tree traversal
// glob.h         - matching types
// grp.h          - group structure
// iconv.h        - codeset conversion facility
// langinfo.h     - language information constants
// libgen.h       - definitions for pattern matching functions
// monetary.h     - monetary types
// mqueue.h       - message queues (REALTIME)
// ndbm.h         - definitions for ndbm database operations
// netdb.h        - definitions for network database operations
// net_if.h       - sockets local interfaces
// netinet/in.h   - Internet address family
// netinet/tcp.h  - definitions for the Internet Transmission Control Protocol (TCP)
// nl_types.h     - data types
// poll.h         - definitions for the poll() function
// pthread.h      - threads
// pwd.h          - password structure
// regex.h        - regular expression matching types
// sched.h        - execution scheduling
// search.h       - search tables
// semaphore.h    - semaphores
// spawn.h        - spawn (ADVANCED REALTIME)
// strings.h      - string operations
// stropts.h      - STREAMS interface (STREAMS)
// sys/ipc.h      - XSI interprocess communication access structure
// syslog.h       - definitions for system error logging
// sys/mman.h     - memory management declarations
// sys/msg.h      - XSI message queue structures
// sys/resource.h - definitions for XSI resource operations
// sys/select.h   - select types
// sys/sem.h      - XSI semaphore facility
// sys/shm.h      - XSI shared memory facility
// sys/socket.h   - main sockets header
// sys/stat.h     - data returned by the stat() function
// sys/statvfs.h  - VFS File System information structure
// sys/time.h     - time types
// sys/times.h    - file access and modification times structure
// sys/types.h    - data types
// sys/uio.h      - definitions for vector I/O operations
// sys/un.h       - definitions for UNIX domain sockets
// sys/utsname.h  - system name structure
// sys/wait.h     - declarations for waiting
// tar.h          - extended tar definitions
// termios.h      - define values for termios
// tgmath.h       - generic macros
// trace.h        - tracing
// utime.h        - access and modification times structure
// utmpx.h        - user accounting database definitions
// wordexp.h      - expansion types
// <unistd.h>     - Various essential POSIX functions and constants
// <dlfcn.h>      - Dynamic linking

};

class help_language
{

};

class help_library
{

};

/********************************************************************************
								global definition
********************************************************************************/

        
/********************************************************************************
								<aio.h> - asynchronous input and output
********************************************************************************/
//class h_aio {
//   int aio_cancel (int fildes, struct aiocb *aiocbp);
//   int aio_error (const struct aiocb *aiocbp);
//   int aio_fsync (int op, struct aiocb *aiocbp);
//   void aio_init (const struct aioinit *init);
//   int aio_read (struct aiocb *aiocbp);
//   ssize_t aio_return (struct aiocb *aiocbp);
//   int aio_suspend (const struct aiocb *const list[], int nent, const struct timespec *timeout);
//   int aio_write (struct aiocb *aiocbp);
//   int lio_listio (int mode, struct aiocb *const list[], int nent, struct sigevent *sig);
//};

struct h_aio{
	int aio_cancel (int fildes, struct aiocb *aiocbp);
	int aio_error (const struct aiocb *aiocbp);
	int aio_fsync (int op, struct aiocb *aiocbp);
	void aio_init (const struct aioinit *init);
	int aio_read (struct aiocb *aiocbp);
	ssize_t aio_return (struct aiocb *aiocbp);
	int aio_suspend (const struct aiocb *const list[], int nent, const struct timespec *timeout);
	int aio_write (struct aiocb *aiocbp);
	int lio_listio (int mode, struct aiocb *const list[], int nent, struct sigevent *sig);
}

/********************************************************************************
								<arpa/inet.h> - definitions for internet operations
********************************************************************************/
class h_arpa_inet {
   uint32_t inet_addr (const char *name);
   int inet_aton (const char *name, struct in_addr *addr);
   uint32_t inet_lnaof (struct in_addr addr);
   struct in_addr inet_makeaddr (uint32_t net, uint32_t local);
   uint32_t inet_netof (struct in_addr addr) ;
   uint32_t inet_network (const char *name) ;
   char * inet_ntoa (struct in_addr addr);
   const char * inet_ntop (int af, const void *cp, char *buf, socklen_t len);
   int inet_pton (int af, const char *cp, void *buf);
};

// cpio.h         - cpio archive values
/********************************************************************************
								<cpio.h> -- 算法
********************************************************************************/
class h_cpio{

};

/********************************************************************************
								<dirent.h> - format of directory entries
********************************************************************************/
class h_dirent{

};

int            alphasort(const struct dirent **, const struct dirent **);
int            closedir(DIR *);
int            dirfd(DIR *);
DIR           *fdopendir(int);
DIR           *opendir(const char *);
struct dirent *readdir(DIR *);
int            readdir_r(DIR *restrict, struct dirent *restrict,
                   struct dirent **restrict);
void           rewinddir(DIR *);
int            scandir(const char *, struct dirent ***,
                   int (*)(const struct dirent *),
                   int (*)(const struct dirent **,
                   const struct dirent **));
void           seekdir(DIR *, long);
long           telldir(DIR *);


// fcntl.h        - file control options
class h_fcntl{

};
// fenv.h         - point environment
class h_fenv{

};
// fmtmsg.h       - message display structures
class h_fmtmsg{

};
// fnmatch.h      - matching types
class h_fnmatch{

};
// ftw.h          - file tree traversal
class h_ftw{

};
// glob.h         - matching types
class h_glob{

};
// grp.h          - group structure
class h_grp{

};
// iconv.h        - codeset conversion facility
class h_iconv{

};
// langinfo.h     - language information constants
class h_langinfo{

};
// libgen.h       - definitions for pattern matching functions
class h_dirent{

};
// monetary.h     - monetary types
class h_monetary{

};
// mqueue.h       - message queues (REALTIME)
class h_mqueue{

};
// ndbm.h         - definitions for ndbm database operations
class h_ndbm{

};
// netdb.h        - definitions for network database operations
class h_netdb{

};
// net_if.h       - sockets local interfaces
class h_net_if{

};
// netinet/in.h   - Internet address family
class h_netinet_in{

};
// netinet/tcp.h  - definitions for the Internet Transmission Control Protocol (TCP)
class h_dirent{

};
// nl_types.h     - data types
class h_nl_types{

};
// poll.h         - definitions for the poll() function
class h_poll{

};
// pthread.h      - threads
class h_pthread{

};
// pwd.h          - password structure
class h_pwd{

};
// regex.h        - regular expression matching types
class h_dirh_regex{

};
// sched.h        - execution scheduling
class h_dih_sched{

};
// search.h       - search tables
class h_search{

};
// semaphore.h    - semaphores
class h_semaphore{

};
// spawn.h        - spawn (ADVANCED REALTIME)
class h_spawn{

};
// strings.h      - string operations
class h_strings{

};
// stropts.h      - STREAMS interface (STREAMS)
class h_stropts{

};
// sys/ipc.h      - XSI interprocess communication access structure
class h_sys_ipc{

};
// syslog.h       - definitions for system error logging
class h_syslog{

};
// sys/mman.h     - memory management declarations
class h_sys_mman{

};
// sys/msg.h      - XSI message queue structures
class h_sys_msg{

};
// sys/resource.h - definitions for XSI resource operations
class h_sys_resource{

};
// sys/select.h   - select types
class h_sys_select{

};
// sys/sem.h      - XSI semaphore facility
class h_sys_sem{

};
// sys/shm.h      - XSI shared memory facility
class h_sys_shm{

};


/********************************************************************************
							<sys/socket.h> - main sockets header
********************************************************************************/
class h_socket 
{
   int     accept(int, struct sockaddr *restrict, socklen_t *restrict);
   int     bind(int, const struct sockaddr *, socklen_t);
   int     connect(int, const struct sockaddr *, socklen_t);
   int     getpeername(int, struct sockaddr *restrict, socklen_t *restrict);
   int     getsockname(int, struct sockaddr *restrict, socklen_t *restrict);
   int     getsockopt(int, int, int, void *restrict, socklen_t *restrict);
   int     listen(int, int);
   ssize_t recv(int, void *, size_t, int);
   ssize_t recvfrom(int, void *restrict, size_t, int,
         struct sockaddr *restrict, socklen_t *restrict);
   ssize_t recvmsg(int, struct msghdr *, int);
   ssize_t send(int, const void *, size_t, int);
   ssize_t sendmsg(int, const struct msghdr *, int);
   ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
         socklen_t);
   int     setsockopt(int, int, int, const void *, socklen_t);
   int     shutdown(int, int);
   int     sockatmark(int);
   int     socket(int, int, int);
   int     socketpair(int, int, int, int [2]);
};
/**
sys/socket.h - main sockets header
#include <sys/socket.h>
DESCRIPTION
The <sys/socket.h> header shall define the socklen_t type, 
                   which is an integer type of width of at least 32 bits; see APPLICATION USAGE.
The <sys/socket.h> header shall define the sa_family_t unsigned integer type.
The <sys/socket.h> header shall define the sockaddr structure, which shall include at least 
the following members:
**/

int     accept(int, struct sockaddr *restrict, socklen_t *restrict);
int     bind(int, const struct sockaddr *, socklen_t);
int     connect(int, const struct sockaddr *, socklen_t);
int     getpeername(int, struct sockaddr *restrict, socklen_t *restrict);
int     getsockname(int, struct sockaddr *restrict, socklen_t *restrict);
int     getsockopt(int, int, int, void *restrict, socklen_t *restrict);
int     listen(int, int);
ssize_t recv(int, void *, size_t, int);
ssize_t recvfrom(int, void *restrict, size_t, int,
        struct sockaddr *restrict, socklen_t *restrict);
ssize_t recvmsg(int, struct msghdr *, int);
ssize_t send(int, const void *, size_t, int);
ssize_t sendmsg(int, const struct msghdr *, int);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
        socklen_t);
int     setsockopt(int, int, int, const void *, socklen_t);
int     shutdown(int, int);
int     sockatmark(int);
int     socket(int, int, int);
int     socketpair(int, int, int, int [2]);



// sys/stat.h     - data returned by the stat() function
// sys/statvfs.h  - VFS File System information structure
// sys/time.h     - time types
// sys/times.h    - file access and modification times structure
// sys/types.h    - data types
// sys/uio.h      - definitions for vector I/O operations
// sys/un.h       - definitions for UNIX domain sockets
// sys/utsname.h  - system name structure
// sys/wait.h     - declarations for waiting
// tar.h          - extended tar definitions
// termios.h      - define values for termios
// tgmath.h       - generic macros
// trace.h        - tracing
// utime.h        - access and modification times structure
// utmpx.h        - user accounting database definitions
// wordexp.h      - expansion types
// <dlfcn.h>      - Dynamic linking

/********************************************************************************
								<dlfcn.h>
********************************************************************************/
class h_dlfcn {
public:
   // const for dlopen function arg flag
   const int RTLD_LAZY;
   const int RTLD_NOW;
   const int RTLD_GLOBAL;
   const int RTLD_LOCAL;

public:
   void *dlopen(const char *filename, int flag);
   char *dlerror(void);
   void *dlsym(void *handle, const char *symbol);
   int dlclose(void *handle);
};

// dlfcn.h - dynamic linking
// SYNOPSIS
//
// DESCRIPTION
//
//The <dlfcn.h> header defines at least the following macros for use in the construction of a dlopen() mode argument:
//RTLD_LAZY
//Relocations are performed at an implementation-dependent time.
//RTLD_NOW
//Relocations are performed when the object is loaded.
//RTLD_GLOBAL
//All symbols are available for relocation processing of other modules.
//RTLD_LOCAL
//All symbols are not made available for relocation processing by other modules.
//The header <dlfcn.h> declares the following functions which may also be defined as macros. Function prototypes must be provided for use with an ISO C compiler.
//Example:
//should add link link option  -ldl  -rdynamic
//remove -static link option

/*
#include <dlfcn.h>

int main(void)
{
	void* handle = 0;
	handle = dlopen(DLL_FILE_NAME, RTLD_NOW);
	func = dlsym(handle, "add");
	printf("%d + %d = %d\n", a, b, func(a, b));
}
*/

/* The MODE argument to `dlopen' contains one of the following: */
#define RTLD_LAZY	0x00001	/* Lazy function call binding.  */
#define RTLD_NOW	0x00002	/* Immediate function call binding.  */
#define	RTLD_BINDING_MASK   0x3	/* Mask of binding time value.  */
#define RTLD_NOLOAD	0x00004	/* Do not load the object.  */
#define RTLD_DEEPBIND	0x00008	/* Use deep binding.  */

/* If the following bit is set in the MODE argument to `dlopen',
   the symbols of the loaded object and its dependencies are made
   visible as if the object were linked directly into the program.  */
#define RTLD_GLOBAL	0x00100

/* Unix98 demands the following flag which is the inverse to RTLD_GLOBAL.
   The implementation does this by default and so we can define the
   value to zero.  */
#define RTLD_LOCAL	0

/* Do not delete object when closed.  */
#define RTLD_NODELETE	0x01000


void *dlopen(const char *filename, int flag);
char *dlerror(void);
void *dlsym(void *handle, const char *symbol);
int dlclose(void *handle);


/********************************************************************************
							<unistd.h> - Various essential POSIX functions and constants
********************************************************************************/
class h_unistd
{
   // Files and Directories <Basic>
   char *getcwd(char *buf, size_t size);
   int mkdir(const char *pathname, mode_t mode);
   int rmdir(const char *pathname);
   int chdir(const char *path);
   int link(const char *oldpath, const char *newpath);
   int unlink(const char *pathname);
   int rename(const char *oldpath, const char *newpath);
   int stat(const char *file_name, struct stat *buf);
   int chmod(const char *path, mode_t mode);
   int chown(const char *path, uid_t owner, gid_t group);
   int utime(const char *filename, struct utimbuf *buf);
   DIR *opendir(const char *name);
   struct dirent *readdir(DIR *dir);
   int closedir(DIR *dir);
   void rewinddir(DIR *dir);

   // Files and Directories <Advance>
   int access(const char *pathname, int mode);
   int open(const char *pathname, int flags);
   int creat(const char *pathname, mode_t mode);
   int close(int fd);
   ssize_t read(int fd, void *buf, size_t count);
   ssize_t write(int fd, const void *buf, size_t count);
   int fcntl(int fd, int cmd);
   int fstat(int filedes, struct stat *buf);
   off_t lseek(int fildes, off_t offset, int whence);
   int dup(int oldfd);
   int dup2(int oldfd, int newfd);
   int pipe(int filedes[2]);
   int mkfifo(const char *pathname, mode_t mode);
   mode_t umask(mode_t mask);
   FILE *fdopen(int fildes, const char *mode);
   int fileno(FILE *stream);
   pid_t fork(void);
   int execl( const char *path, const char *arg, ...);
   int execlp( const char *file, const char *arg, ...);
   int execv( const char *path, char *const argv[]);
   int execvp( const char *file, char *const argv[]);
   pid_t waitpid(pid_t pid, int *status, int options);
   pid_t waitpid(pid_t pid, int *status, int options);
   void _exit(int status);
   int kill(pid_t pid, int sig);
   unsigned int sleep(unsigned int seconds);
   int pause(void);
   unsigned int alarm(unsigned int seconds);


};

char *getcwd(char *buf, size_t size);
//get current working directory
int mkdir(const char *pathname, mode_t mode);
// create a directory
int rmdir(const char *pathname);
// delete a directory
int chdir(const char *path);
// change working directory
int link(const char *oldpath, const char *newpath);
// make a new name for a file
int unlink(const char *pathname);
// delete a name and possibly the file it refers to
int rename(const char *oldpath, const char *newpath);
// change the name or location of a file
int stat(const char *file_name, struct stat *buf);
// get file status
int chmod(const char *path, mode_t mode);
// change permissions of a file
int chown(const char *path, uid_t owner, gid_t group);
// change ownership of a file
int utime(const char *filename, struct utimbuf *buf);
// change access and/or modification times of an inode
DIR *opendir(const char *name);
// open a directory
struct dirent* readdir(DIR *dir);
// read directory entry
int closedir(DIR *dir);
// close a directory
void rewinddir(DIR *dir);
// reset directory stream

int access(const char *pathname, int mode);
// check user's permissions for a file
int open(const char *pathname, int flags);
// open and possibly create a file or device
int creat(const char *pathname, mode_t mode);
// open and possibly create a file or device
int close(int fd);
// close a file descriptor
ssize_t read(int fd, void *buf, size_t count);
// read from a file descriptor
ssize_t write(int fd, const void *buf, size_t count);
// write to a file descriptor
int fcntl(int fd, int cmd);
// manipulate file descriptor
int fstat(int filedes, struct stat *buf);
// get file status
off_t lseek(int fildes, off_t offset, int whence);
// reposition read/write file offset
int dup(int oldfd);
// duplicate a file descriptor
int dup2(int oldfd, int newfd);
// duplicate a file descriptor
int pipe(int filedes[2]);
// create pipe
int mkfifo(const char *pathname, mode_t mode);
// make a FIFO special file (a named pipe)
mode_t umask(mode_t mask);
// set file creation mask
FILE *fdopen(int fildes, const char *mode);
// associate a stream with an existing file descriptor
int fileno(FILE *stream);
// retun file descriptor of stream

#endif
//end of file
